import { _decorator, Component, Node, utils } from 'cc';
import { BehaviorTree } from '../BehaviorTree';

import { BTree } from '../utils/BTree';
import { CustomNode } from '../BNode/CustomNode';
const { ccclass, property } = _decorator;

const b = BTree;

@ccclass('Example_3')
export class Example_3 extends Component {
   
    behaviorTree = new BehaviorTree();
    customNode = new CustomNode();

    start() {
        this.test1();
    }

    //测试自定义节点
    test1() {
        const data = { x: 10, y: 'hello' };
        this.behaviorTree.blackBoard = data;
        this.behaviorTree.root.addChild(
            this.customNode,
            b.call(() => {
                console.log('end');
            }),
        );
        this.behaviorTree.run();
        console.log('start');
        this.testSleep();
    }

    testSleep() {
        this.scheduleOnce(() => {
            this.customNode.done();
        }, 4);
    }

    update(deltaTime: number) {
        this.behaviorTree.update(deltaTime);
    }

}
